//
//  NemoDrawingCommand.m
//  NemoSDKDemo
//
//  Created by NemoSDKDemo on 19/5/27.
//  Copyright © 2019 JackYang. All rights reserved.
//

#import "NemoDrawingCommand.h"
#import <GLKit/GLKit.h>
#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>

static CGPoint midPoint(CGPoint p1, CGPoint p2)
{
    return CGPointMake((p1.x + p2.x) * 0.5, (p1.y + p2.y) * 0.5);
}

static CGPoint perpendicular(CGPoint p1, CGPoint p2) {
    CGPoint ret;
    ret.x = p2.y - p1.y;
    ret.y = -1 * (p2.x - p1.x);
    return ret;
}

static CGFloat distanceOfPoints(CGPoint fPoint, CGPoint tPoint)
{
    CGFloat deltaX = ABS(tPoint.x - fPoint.x);
    CGFloat deltaY = ABS(tPoint.y - fPoint.y);
    
    return sqrtf((deltaX*deltaX + deltaY*deltaY));
}


CGFloat angleBetweenPoints(CGPoint first, CGPoint second) {
    CGFloat height = second.y - first.y;
    CGFloat width = second.x - first.x;
    if (width == 0)
    {
        return height>=0 ? M_PI_2 : (3*M_PI_2);
    }
    
    CGFloat rads = atanf(height/width);
    
    
    
    if (height<0 && width<0)
    {
        rads += M_PI;
    }
    else if (height<0)
    {
        rads += (2*M_PI);
    }
    else if (width<0)
    {
        rads += M_PI;
    }
    
    return rads;
}

CGFloat angleBetweenLines(CGPoint line1Start, CGPoint line1End, CGPoint line2Start, CGPoint line2End)
{
    CGFloat angle1 = angleBetweenPoints(line1Start, line1End);
    CGFloat angle2 = angleBetweenPoints(line2Start, line2End);
    
//    CGFloat a1 = angleBetweenPoints(CGPointMake(0, 0), CGPointMake(1, 1));
//    CGFloat a2 = angleBetweenPoints(CGPointMake(0, 0), CGPointMake(-1, 1));
//    CGFloat a3 = angleBetweenPoints(CGPointMake(0, 0), CGPointMake(-1, -1));
//    CGFloat a4 = angleBetweenPoints(CGPointMake(0, 0), CGPointMake(1, -1));
    
    
    angle1 = angle2-angle1;
    if (angle1<0)
    {
        angle1 += 2*M_PI;
    }
    
    return angle1;
    
}

#pragma mark - DrawingBezierCommand
#define BEZIER_BUFFER_COUNT_ONCE (50)
#define BEZIER_SAMPLE_LIMIT_DISTANCE (0.01)

@interface DrawingBezierCommand()
{
    GLKVector3 *pVerticesBuf;
    int verticesBufCapability;
    int verticesTotalCount;
    int verticesDrawnCount;
}

@property (nonatomic, strong) NSMutableArray *touchPoints;
@property (nonatomic, strong) NSValue *lastSamplePoint1;
@property (nonatomic, strong) NSValue *lastSamplePoint2;

@end

@implementation DrawingBezierCommand

@synthesize lineColor = _lineColor;
@synthesize lineWidth = _lineWidth;
@synthesize aspect = _aspect;

- (id)initWithSequeceId:(int)seqId
{
    self = [super init];
    if (self != nil) {
        _sequenceId = seqId;
        
        self.touchPoints = [[NSMutableArray alloc] init];
        
        verticesBufCapability = BEZIER_BUFFER_COUNT_ONCE * 2;
        pVerticesBuf = (GLKVector3*) malloc(sizeof(GLKVector3)*verticesBufCapability);
        if (pVerticesBuf == NULL)
        {
            NSLog(@"%s : malloc vertices buffer fail",__func__);
            verticesBufCapability = 0;
        }
        verticesTotalCount = 0;
    }
    return self;
}

-(void)dealloc
{
    if (pVerticesBuf != NULL)
    {
        free(pVerticesBuf);
        pVerticesBuf = NULL;
    }
}

-(void)addTriangleStripVerticesForPoint:(CGPoint)point withPrev:(CGPoint)prevPoint next:(CGPoint)nextPoint
{
    if (pVerticesBuf == NULL)
    {
        verticesBufCapability = BEZIER_BUFFER_COUNT_ONCE * 2;
        pVerticesBuf = (GLKVector3*)malloc(sizeof(GLKVector3) * verticesBufCapability);
        if (pVerticesBuf == NULL)
        {
            NSLog(@"%s : malloc vertices buffer fail",__func__);
            verticesBufCapability = 0;
            return;
        }
    }
    else
    {
        if (verticesTotalCount == verticesBufCapability)
        {
            verticesBufCapability += BEZIER_BUFFER_COUNT_ONCE;
            pVerticesBuf = realloc(pVerticesBuf, sizeof(GLKVector3) * verticesBufCapability);
            if (pVerticesBuf == NULL)
            {
                NSLog(@"%s : realloc vertices buffer fail",__func__);
                verticesBufCapability = 0;
                return;
            }
        }
    }
    
    float toTravel = self.lineWidth / 2.0;
    
    CGFloat distance1 = distanceOfPoints(prevPoint, point);
    CGFloat distance2 = distanceOfPoints(point, nextPoint);
    CGFloat difX = nextPoint.x - point.x;
    CGFloat difY = nextPoint.y - point.y;
    difX *= distance1/distance2;
    difY *= distance1/distance2;
    CGPoint ref = CGPointMake(point.x+difX, point.y+difY);
    ref = midPoint(ref, prevPoint);
    CGFloat angle = angleBetweenLines(point, prevPoint, point, ref);
    CGFloat distance3 = distanceOfPoints(point, ref);
    
//    NSLog(@"%s, angle=%f, angle degree = %d", __FUNCTION__, angle, (int)(angle*180/M_PI));
    
    if ((sinf(angle) > -0.000001 && sinf(angle) < 0.000001) ||
        (distance3 > -0.000001 && distance3 < 0.000001))
    {
        [self addTriangleStripVerticesForPrevious:prevPoint next:point isReversed:NO];
        
        NSLog(@"%s detect sinf = 0",__func__);
        return;
    }
    
    CGFloat radio = 1/sinf(angle);
    if (radio>1.5)
        radio = 1.5;
    else if (radio<-1.5)
        radio = -1.5;
//    if (radio>1.0)
//        radio = 1.0;
//    else if (radio<-1.0)
//        radio = -1.0;
    
    CGFloat width = toTravel * radio;
    radio = width/distance3;
    

    difX = ref.x - point.x;
    difY = ref.y - point.y;
    difX *= radio;
    difY *= radio * self.aspect;
    
    GLKVector3 stripPoint = {point.x + difX, point.y + difY, 0.0 };
    memcpy(pVerticesBuf+verticesTotalCount, &stripPoint, sizeof(GLKVector3));
    verticesTotalCount++;
    
    GLKVector3 stripPoint1 = {point.x - difX, point.y - difY, 0.0 };
    memcpy(pVerticesBuf+verticesTotalCount, &stripPoint1, sizeof(GLKVector3));
    verticesTotalCount++;

    if (isnan(stripPoint.x) || isnan(stripPoint.y) ||
        isinf(stripPoint.x) || isinf(stripPoint.y) ||
        stripPoint.x>1 || stripPoint.y>1 ||
        stripPoint.x < -1 || stripPoint.y <-1)
    {
        NSLog(@"exceptional stripPoint");
        NSLog(@"%s, stripPoint : %f, %f", __FUNCTION__, stripPoint.x, stripPoint.y);
        NSLog(@"%s, stripPoint1 : %f, %f",__FUNCTION__, stripPoint1.x, stripPoint1.y);
    }
}

- (void)addTriangleStripVerticesForPrevious:(CGPoint)previous
                                     next:(CGPoint)next
                               isReversed:(BOOL)isReversed
{
    if (pVerticesBuf == NULL)
    {
        verticesBufCapability = BEZIER_BUFFER_COUNT_ONCE * 2;
        pVerticesBuf = (GLKVector3*)malloc(sizeof(GLKVector3) * verticesBufCapability);
        if (pVerticesBuf == NULL)
        {
            NSLog(@"%s : malloc vertices buffer fail",__func__);
            verticesBufCapability = 0;
            return;
        }
    }
    else
    {
        if (verticesTotalCount == verticesBufCapability)
        {
            verticesBufCapability += BEZIER_BUFFER_COUNT_ONCE;
            pVerticesBuf = realloc(pVerticesBuf, sizeof(GLKVector3) * verticesBufCapability);
            if (pVerticesBuf == NULL)
            {
                NSLog(@"%s : realloc vertices buffer fail",__func__);
                verticesBufCapability = 0;
                return;
            }
        }
    }
    
    float toTravel = self.lineWidth / 2.0;
    
    CGPoint p = perpendicular(previous, next);
    CGPoint ref = CGPointMake(next.x+p.x, next.y+p.y);
    
    float distance = distanceOfPoints(next, ref);
    float difX = ref.x - next.x;
    float difY = ref.y - next.y;
    float ratio = toTravel / distance;
    
    if (isReversed)
    {
        ratio = ratio * -1;
    }
    
    difX = difX * ratio;
    difY = difY * ratio * self.aspect;
    
    GLKVector3 stripPoint = {next.x + difX, next.y + difY, 0.0 };
    memcpy(pVerticesBuf+verticesTotalCount, &stripPoint, sizeof(GLKVector3));
    verticesTotalCount++;
    
    GLKVector3 stripPoint1 = {next.x - difX, next.y - difY, 0.0 };
    memcpy(pVerticesBuf+verticesTotalCount, &stripPoint1, sizeof(GLKVector3));
    verticesTotalCount++;
    
    if (isnan(stripPoint.x) || isnan(stripPoint.y) ||
        isinf(stripPoint.x) || isinf(stripPoint.y) ||
        stripPoint.x>1 || stripPoint.y>1 ||
        stripPoint.x < -1 || stripPoint.y <-1)
    {
        NSLog(@"exceptional stripPoint");
        NSLog(@"%s, stripPoint : %f, %f", __FUNCTION__, stripPoint.x, stripPoint.y);
        NSLog(@"%s, stripPoint1 : %f, %f",__FUNCTION__, stripPoint1.x, stripPoint1.y);
    }
    
}

- (void)setInitialPoint:(CGPoint)firstPoint
{
    [self moveToPoint:firstPoint];
//    [_touchPoints addObject:[NSValue valueWithCGPoint:firstPoint]];
}

- (BOOL)moveToPoint:(CGPoint)point
{
//    if (verticesTotalCount > 0)
//        return NO;
//    
//    self.lineWidth = 0.05;
//    
//    [self addTriangleStripVerticesForPrevious:CGPointMake(-0.2, 0)
//                                         next:CGPointMake(-0.5, 0)
//                                   isReversed:YES];
//    
//    [self addTriangleStripVerticesForPoint:CGPointMake(-0.2, 0)
//                                  withPrev:CGPointMake(-0.5, 0)
//                                      next:CGPointMake(0, 0)];
//    
//    [self addTriangleStripVerticesForPoint:CGPointMake(0, 0)
//                                  withPrev:CGPointMake(-0.2, 0)
//                                      next:CGPointMake(0.2, 0)];
//    
//    [self addTriangleStripVerticesForPoint:CGPointMake(0.2, 0)
//                                  withPrev:CGPointMake(0, 0)
//                                      next:CGPointMake(0.5, 0)];
//    
//    [self addTriangleStripVerticesForPrevious:CGPointMake(0.2, 0)
//                                         next:CGPointMake(0.5, 0)
//                                   isReversed:NO];
//    
//    return YES;
    
    BOOL ret = NO;
    
    NSLog(@"%s point (%f, %f)",__FUNCTION__, point.x, point.y);
    
    if (point.x > 1 || point.y > 1)
        NSLog(@"move to exceptional GL point");
    
    CGPoint lastPoint = [[_touchPoints lastObject] CGPointValue];
    CGFloat distance =  distanceOfPoints(lastPoint, point);
    if (distance < 0.00001)
    {
        NSLog(@"%s distance = %f", __FUNCTION__, distance);
        return ret;
    }

    [_touchPoints addObject:[NSValue valueWithCGPoint:point]];
    NSUInteger touchCount = _touchPoints.count;
    if (touchCount % 3 == 2 && touchCount >= 5)
    {
        NSLog(@"********* start calculate a new bezier ************");
        CGPoint bezierPathPoint1, bezierPathPoint2, bezierCtlPoint1, bezierCtlPoint2;
        
        bezierCtlPoint1 = [[_touchPoints objectAtIndex:touchCount-4] CGPointValue];
        if (touchCount == 5)
        {
            bezierPathPoint1 = [[_touchPoints objectAtIndex:0] CGPointValue];
        }
        else
        {
            CGPoint point1 = [[_touchPoints objectAtIndex:touchCount-6] CGPointValue];
            bezierPathPoint1 = midPoint(point1, bezierCtlPoint1);
        }
        
        bezierCtlPoint2 = [[_touchPoints objectAtIndex:touchCount-3] CGPointValue];
        bezierPathPoint2 = midPoint(bezierCtlPoint2, point);
        
        CGFloat limitDistance = _lineWidth/3;
        if (limitDistance < BEZIER_SAMPLE_LIMIT_DISTANCE)
        {
            limitDistance = BEZIER_SAMPLE_LIMIT_DISTANCE;
        }
        CGFloat distance = distanceOfPoints(bezierPathPoint1, bezierPathPoint2);
        int sampleCount = (int)(distance/limitDistance);
        
        NSLog(@"%s distance=%f sampleCount=%d", __FUNCTION__, distance, sampleCount);
        if (sampleCount <= 1)
        {
            if (_lastSamplePoint1 != nil)
            {
                if (_lastSamplePoint2 != nil)
                {
                    [self addTriangleStripVerticesForPoint:[_lastSamplePoint1 CGPointValue]
                                                  withPrev:[_lastSamplePoint2 CGPointValue]
                                                      next:bezierPathPoint2];
                }
                else
                {
                    [self addTriangleStripVerticesForPrevious:bezierPathPoint2
                                                         next:[_lastSamplePoint1 CGPointValue]
                                                   isReversed:YES];
                }
            }
            else
            {
                [self addTriangleStripVerticesForPrevious:bezierPathPoint2
                                                     next:bezierPathPoint1
                                               isReversed:NO];
                self.lastSamplePoint1 = [NSValue valueWithCGPoint:bezierPathPoint1];
            }
            
            self.lastSamplePoint2 = self.lastSamplePoint1;
            self.lastSamplePoint1 = [NSValue valueWithCGPoint:bezierPathPoint2];
        }
        else
        {
            for (int i = 0; i < sampleCount+1 ; i++)
            {
                if (i==0 && _lastSamplePoint1!=nil)
                    continue;
                
                CGFloat t = (1.0/sampleCount)*i;
                CGFloat ptX = bezierPathPoint1.x * powf(1-t, 3) +
                bezierCtlPoint1.x * 3 * powf(1-t, 2) * t +
                bezierCtlPoint2.x * 3 * (1-t) * powf(t, 2) +
                bezierPathPoint2.x * powf(t, 3);
                
                CGFloat ptY = bezierPathPoint1.y * powf(1-t, 3) +
                bezierCtlPoint1.y * 3 * powf(1-t, 2) * t +
                bezierCtlPoint2.y * 3 * (1-t) * powf(t, 2) +
                bezierPathPoint2.y * powf(t, 3);
                
                CGPoint currentSamplePoint = CGPointMake(ptX, ptY);
                //            NSLog(@"current(%f,%f) , last1(%@), last2(%@)", ptX, ptY, _lastSamplePoint1, _lastSamplePoint2);
                if (_lastSamplePoint1 != nil)
                {
                    if (_lastSamplePoint2 != nil)
                    {
                        [self addTriangleStripVerticesForPoint:[_lastSamplePoint1 CGPointValue]
                                                      withPrev:[_lastSamplePoint2 CGPointValue]
                                                          next:currentSamplePoint];
                    }
                    else
                    {
                        [self addTriangleStripVerticesForPrevious:currentSamplePoint
                                                             next:[_lastSamplePoint1 CGPointValue]
                                                       isReversed:YES];
                    }
                }
                
                self.lastSamplePoint2 = self.lastSamplePoint1;
                self.lastSamplePoint1 = [NSValue valueWithCGPoint:currentSamplePoint];
            }
        }

        ret = YES;
    }

    return   ret;
}

- (void)moveEnd
{
    _isFinished = YES;
    
    NSUInteger touchCount = _touchPoints.count;
    if (touchCount < 5)
    {
        for (NSInteger i=0; i< touchCount; i++)
        {
            NSLog(@"%s extra handle point(%@) at %ld", __FUNCTION__, [_touchPoints objectAtIndex:i],(unsigned long)i);
            if (i-1>=0 && i+1<touchCount)
            {
                [self addTriangleStripVerticesForPoint:[[_touchPoints objectAtIndex:i] CGPointValue]
                                              withPrev:[[_touchPoints objectAtIndex:i-1] CGPointValue]
                                                  next:[[_touchPoints objectAtIndex:i+1] CGPointValue]];
            }
            else if (i-1<0 && i+1<touchCount)
            {
                [self addTriangleStripVerticesForPrevious:[[_touchPoints objectAtIndex:i+1] CGPointValue]
                                                     next:[[_touchPoints objectAtIndex:i] CGPointValue]
                                               isReversed:YES];
            }
            else if (i-1>=0 && i+1>=touchCount)
            {
                [self addTriangleStripVerticesForPrevious:[[_touchPoints objectAtIndex:i-1] CGPointValue]
                                                     next:[[_touchPoints objectAtIndex:i] CGPointValue]
                                               isReversed:NO];
            }
        }
    }
    else
    {
        NSUInteger extraCount = touchCount % 3;
        extraCount += 2;
        if (extraCount > 3)
            extraCount = extraCount-3;
        
        for (NSUInteger i = touchCount-extraCount; i<touchCount; i++)
        {
            NSLog(@"%s extra handle point(%@) at %ld", __FUNCTION__, [_touchPoints objectAtIndex:i],(unsigned long)i);
            if (i+1 < touchCount)
            {
                [self addTriangleStripVerticesForPoint:[_lastSamplePoint1 CGPointValue]
                                              withPrev:[_lastSamplePoint2 CGPointValue]
                                                  next:[[_touchPoints objectAtIndex:i+1] CGPointValue]];
            }
            else
            {
                [self addTriangleStripVerticesForPrevious:[[_touchPoints objectAtIndex:i-1] CGPointValue]
                                                     next:[[_touchPoints objectAtIndex:i] CGPointValue]
                                               isReversed:NO];
            }
            
            _lastSamplePoint2 = _lastSamplePoint1;
            _lastSamplePoint1 = [_touchPoints objectAtIndex:i];
        }
    }
}

- (void)draw
{
    int countToDraw = verticesTotalCount-verticesDrawnCount;
//    NSLog(@"%s totalcount=%d, drawncount=%d, countToDrawn= %d", __FUNCTION__, verticesTotalCount, verticesDrawnCount, countToDraw);
    if (countToDraw > 0)
    {
        GLuint vertexBufferID;
        
        glGenBuffers(1, &vertexBufferID);
        glBindBuffer(GL_ARRAY_BUFFER, vertexBufferID);
        
        glEnableVertexAttribArray(GLKVertexAttribPosition);
        glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, sizeof(GLKVector3), 0);
        
        GLKVector3 *pAddress = NULL;
        if (verticesDrawnCount==0)
        {
            pAddress = pVerticesBuf+verticesDrawnCount;
        }
        else
        {
            //need to involve the last two vertex drawn;
            pAddress = pVerticesBuf+verticesDrawnCount - 2;
            countToDraw = countToDraw + 2;
        }
        
        glBufferData(GL_ARRAY_BUFFER,
                     sizeof(GLKVector3) * countToDraw,
                     pAddress,
                     GL_DYNAMIC_DRAW);
        
//        NSLog(@"****************************************");
//        for(int i=0; i<countToDraw ; i++)
//        {
//            NSLog(@"draw point x=%f, y=%f", (*(pAddress+i)).x, (*(pAddress+i)).y);
//        }
        
        CGFloat red, green, blue, alpha;
        [self.lineColor getRed:&red green:&green blue:&blue alpha:&alpha];
        GLKBaseEffect *baseEffect = [[GLKBaseEffect alloc] init];
        baseEffect.useConstantColor = GL_TRUE;
        baseEffect.constantColor = GLKVector4Make(red, green, blue, alpha);
        [baseEffect prepareToDraw];
        
        glEnableVertexAttribArray(GLKVertexAttribPosition);
        glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, sizeof(GLKVector3), NULL);
        
//        glDisable(GL_BLEND);
//        if (_isErasered)
//        {
//            glDisable(GL_BLEND);
//        }
//        else
//        {
//            glEnable(GL_BLEND);
//            glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
//        }
        
        glDrawArrays(GL_TRIANGLE_STRIP, 0, countToDraw);
        
//        baseEffect.constantColor = GLKVector4Make(1-red, 1-green, 1-blue, 1.0);
//        [baseEffect prepareToDraw];
//        glDrawArrays(GL_LINE_STRIP, 0, countToDraw);
        
        glFlush();
        
        glDeleteBuffers(1, &vertexBufferID);
        
        verticesDrawnCount = verticesTotalCount;
    }
}

-(void)redraw
{
    if (verticesTotalCount > 0)
    {
        GLuint vertexBufferID;
        
        glGenBuffers(1, &vertexBufferID);
        glBindBuffer(GL_ARRAY_BUFFER, vertexBufferID);
        
        glEnableVertexAttribArray(GLKVertexAttribPosition);
        glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, sizeof(GLKVector3), 0);
        
        glBufferData(GL_ARRAY_BUFFER,
                     sizeof(GLKVector3) * verticesTotalCount,
                     pVerticesBuf,
                     GL_DYNAMIC_DRAW);
        
        //    NSLog(@"**************************");
        //    for(GLKVector3 *p = pVerticesBuf; p < pVerticesBuf+verticesTotalCount; p++)
        //    {
        //        NSLog(@"vertice x=%f, y= %f", (*p).x, (*p).y);
        //    }
        
        CGFloat red, green, blue, alpha;
        [self.lineColor getRed:&red green:&green blue:&blue alpha:&alpha];
        GLKBaseEffect *baseEffect = [[GLKBaseEffect alloc] init];
        baseEffect.useConstantColor = GL_TRUE;
        baseEffect.constantColor = GLKVector4Make(red, green, blue, alpha);
        [baseEffect prepareToDraw];
        
        glEnableVertexAttribArray(GLKVertexAttribPosition);
        glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, sizeof(GLKVector3), NULL);
        
//        if (_isErasered)
//        {
//            glDisable(GL_BLEND);
//        }
//        else
//        {
//            glEnable(GL_BLEND);
//            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//        }

        glDrawArrays(GL_TRIANGLE_STRIP, 0, verticesTotalCount);
        
        glFlush();
        
        glDeleteBuffers(1, &vertexBufferID);
        
        verticesDrawnCount = verticesTotalCount;
    }
}

-(NSArray*)getTrackPoints
{
    return _touchPoints;
}

-(BOOL)finished
{
    return _isFinished;
}

@end

#pragma mark - DrawingPointerCommand

@implementation DrawingPointerCommand

@synthesize lineColor = _lineColor;
@synthesize lineWidth = _lineWidth;
@synthesize aspect = _aspect;

- (void)setInitialPoint:(CGPoint)firstPoint
{
    position = firstPoint;
}

-(BOOL)moveToPoint:(CGPoint)endPoint
{
    position = endPoint;
    
    return YES;
}

-(void)moveEnd
{
    
}

-(void)draw
{
}

@end


#pragma mark - DrawingLineCommand

@implementation DrawingLineCommand

@synthesize lineColor = _lineColor;
@synthesize lineWidth = _lineWidth;
@synthesize aspect = _aspect;

- (void)setInitialPoint:(CGPoint)aFirstPoint
{
    firstPoint = aFirstPoint;
}

-(BOOL)moveToPoint:(CGPoint)point
{
    lastPoint = point;
    
    return YES;
}

-(void)moveEnd
{
    
}

- (void)draw
{
}

@end


#pragma mark - DrawingRectangleCommand
@implementation DrawingRectangleCommand

@synthesize lineColor = _lineColor;
@synthesize lineWidth = _lineWidth;
@synthesize aspect = _aspect;

- (void)setInitialPoint:(CGPoint)afirstPoint
{
    firstPoint = afirstPoint;
}

- (BOOL)moveToPoint:(CGPoint)point
{
    lastPoint = point;
    
    return YES;
}

-(void)moveEnd
{
    
}

- (void)draw
{
}

@end


#pragma mark - ACEDrawingEllipseTool

@implementation DrawingEllipseCommand

@synthesize lineColor = _lineColor;
@synthesize lineWidth = _lineWidth;
@synthesize aspect = _aspect;

- (void)setInitialPoint:(CGPoint)afirstPoint
{
    firstPoint = afirstPoint;
}

- (BOOL)moveToPoint:(CGPoint)point
{
    lastPoint = point;
    
    return YES;
}

-(void)moveEnd
{
    
}

- (void)draw
{
}

@end
